package cj.web.portal.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cj.web.admin.constants.Constants;
import cj.web.kly.constants.GroupPeopleTypeEnum;
import cj.web.kly.domain.GroupDep;
import cj.web.kly.domain.GroupInfor;
import cj.web.kly.domain.GroupPeople;
import cj.web.portal.dao.GroupDepVoDAO;
import cj.web.portal.dao.GroupInforVoDAO;
import cj.web.portal.dao.GroupPeopleVoDAO;
import net.paoding.rose.web.var.Model;

@Service
public class InstitutionService {

	@Autowired
    private GroupPeopleVoDAO groupPeopleVoDAO;
	@Autowired
    private GroupDepVoDAO groupDepVoDAO;
	@Autowired
    private GroupInforVoDAO groupInforVoDAO;
	
	/**
	 * 请求部门列表
	 * @param groupId
	 * @return
	 */
	public List<GroupDep> queryGroupDeplis(int groupId){
		return groupDepVoDAO.queryNameByGroupId(groupId);
	}
	
	/**
	 * 请求机构
	 * @param groupId
	 * @return
	 */
	public GroupInfor queryGroupInforlis(int groupId){
		return groupInforVoDAO.queryById(groupId);
	}
	
	/**
	 * 请求部门列表
	 * @param groupId
	 * @return
	 */
	public Model queryGroupDeplis(Model model,int groupId){
		GroupInfor groupInfor = groupInforVoDAO.queryById(groupId);
		model.add("groupInfor", groupInfor);
		List<GroupDep> groupDeplis = groupDepVoDAO.queryNameByGroupId(groupId);
		model.add("groupDeplis", groupDeplis);
		return model;
	}
	
	/**
	 * 请求部门列表
	 * @param depId
	 * @return
	 */
	public Map queryGroupDeplisByDepId(int groupId,int depId){
		//查询组织部门信息
		Map rep = new HashMap();
		GroupInfor groupInfor = groupInforVoDAO.queryById(groupId);
		List<GroupDep> groupDeplis = groupDepVoDAO.queryNameByGroupId(groupId);
		rep.put("groupInfor", groupInfor);
		rep.put("groupDeplis", groupDeplis);
		return rep;
	}
	
	/**
	 * 通过部门depId查看部门详情
	 * @param depId
	 * @return
	 */
	public JSONObject queryGroupDepDetail(int depId){
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		//查询组织部门信息
		GroupDep groupDep = groupDepVoDAO.queryNameBydepId(depId);
		//部门负责人
		List<GroupPeople> mamager = groupPeopleVoDAO.queryBydepId(depId, GroupPeopleTypeEnum.TYPE_0.getValue());
		//普通人员
		List<GroupPeople> people = groupPeopleVoDAO.queryBydepId(depId, GroupPeopleTypeEnum.TYPE_1.getValue());
		
		jo.put("groupDep", groupDep);//部门
		jo.put("mamager", mamager);//部门负责人
		jo.put("people", people);//部门成员
		return jo;
	}
}